package com.chapter20.demo2;

import java.util.concurrent.Callable;

public class FactorialTask implements Callable<Integer> {
    private int number;

    public FactorialTask(int number) {
        this.number = number;
    }

    //递归调用计算某个数的阶乘
    public int calculate(int num){
        if(num<0){
            throw new IllegalArgumentException();
        }
        if(num ==0 || 1==num)
            return 1;
        return num*calculate(num-1);
    }

    @Override
    public Integer call() throws Exception {
        return calculate(number);
    }
}
